package offer;

import java.util.Deque;
import java.util.LinkedList;

/**
 * 描述:剑指 Offer 30. 包含min函数的栈
 *
 * @author Madison You
 * @created 21:41
 */
public class Easy_30_MinStack {
    public static void main(String[] args) {
        Easy_30_MinStack minStack = new Easy_30_MinStack();
        minStack.push(0);
        minStack.push(1);
        minStack.push(0);
        minStack.min();
        minStack.pop();
        minStack.min();
    }

    private Deque<Integer> deque1 = null;

    private Deque<Integer> deque2 = null;

    public Easy_30_MinStack() {
        deque1 = new LinkedList<>();
        deque2 = new LinkedList<>();
    }

    public void push(int x) {
        deque1.push(x);
        if (deque2.isEmpty() || deque2.peek() >= x) {
            deque2.push(x);
        }
    }

    public void pop() {
        if (deque1.pop().equals(deque2.peek())) {
            deque2.pop();
        }
    }

    public int top() {
        return deque1.peek();
    }

    public int min() {
        return deque2.peek();
    }

}
